/*
 * Copyright (C) 2022 Huawei Technologies Co., Ltd.
 * Licensed under the Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *     http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
 * PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
#include "ta_verify_key.h"
#include <tee_log.h>
#include <crypto_wrapper.h>
#include "ta_load_key.h"

#define RSA4096_MODULE_LEN 512
#define EXE_LEN      3

#ifdef CONFIG_TA_SIGN_MDC
static const rsa_pub_key_t  g_ta_verify_pub_key = {
    {
        0x01, 0x00, 0x01
    },
    EXE_LEN,
    {
        0xd5, 0x3b, 0x5c, 0x8b, 0xe4, 0xb7, 0xf5, 0xb3, 0xd0, 0xbc, 0x83, 0x99, 0x0e, 0x7d, 0xf5,
        0x67, 0xaa, 0x5f, 0x5e, 0x3f, 0xc5, 0x9e, 0xdd, 0x1c, 0x36, 0xcd, 0x46, 0x99, 0x80, 0x13,
        0x27, 0x7e, 0xf3, 0x39, 0xde, 0x9d, 0xae, 0x7a, 0x39, 0x3f, 0x44, 0x97, 0xbe, 0xc9, 0x5c,
        0x07, 0xd7, 0xf8, 0xfe, 0x7b, 0x23, 0xdd, 0xb7, 0x4f, 0xf1, 0xf0, 0xc1, 0x00, 0x61, 0xbe,
        0x0a, 0x93, 0x4d, 0x28, 0xd1, 0x9d, 0xe5, 0xa7, 0x28, 0xe8, 0x76, 0x81, 0x46, 0xb4, 0x71,
        0x50, 0xbc, 0xe7, 0xda, 0x1e, 0xb2, 0xb7, 0xc7, 0x75, 0xd9, 0x5b, 0xdd, 0x53, 0xcd, 0xac,
        0x41, 0xa3, 0xed, 0x84, 0x9b, 0xd5, 0xf0, 0xd0, 0x02, 0x27, 0x6e, 0xb2, 0x55, 0x84, 0x93,
        0x9e, 0x62, 0xd8, 0x6e, 0xc7, 0x87, 0x22, 0xec, 0x99, 0x6f, 0x0f, 0xd1, 0x06, 0x24, 0x5a,
        0xd3, 0x8a, 0x53, 0x8c, 0xd5, 0x70, 0xa3, 0x77, 0x00, 0xef, 0x70, 0x67, 0xa2, 0xbf, 0x44,
        0x14, 0x8f, 0x70, 0x97, 0x78, 0x9b, 0x53, 0x64, 0xdd, 0x24, 0x95, 0x90, 0x90, 0x7c, 0x0a,
        0x87, 0xe5, 0xdb, 0x9d, 0xb5, 0xb1, 0x26, 0xfd, 0x4e, 0xb3, 0xf7, 0x0f, 0x01, 0xc5, 0x81,
        0x13, 0xa5, 0xe7, 0xd0, 0x5c, 0x3c, 0x07, 0xe3, 0xa2, 0x9e, 0xd9, 0x1c, 0x21, 0x76, 0xe2,
        0x19, 0x02, 0x6c, 0x84, 0xa3, 0x51, 0x5f, 0x11, 0x5e, 0x3a, 0xb2, 0xb2, 0x30, 0x88, 0xe4,
        0xf9, 0x13, 0x0e, 0x2a, 0x97, 0x59, 0xce, 0x39, 0xba, 0xe7, 0xe7, 0x57, 0xfa, 0xe2, 0x71,
        0x1c, 0x10, 0x21, 0x2a, 0x27, 0x0a, 0xfc, 0x2e, 0x14, 0xf4, 0x92, 0x4f, 0x20, 0xba, 0x10,
        0x1e, 0xe6, 0x12, 0x5e, 0x65, 0x8b, 0xf2, 0x35, 0x95, 0x36, 0x19, 0xa2, 0x92, 0x83, 0xf8,
        0x31, 0x81, 0x3f, 0xee, 0x3c, 0x77, 0x29, 0xf3, 0x81, 0xbc, 0x8b, 0x2c, 0x2f, 0x41, 0x21,
        0x1e, 0x74, 0xbf, 0x25, 0x88, 0x0f, 0x7b, 0xbc, 0x96, 0xd3, 0x57, 0x1b, 0x49, 0x46, 0x97,
        0x73, 0xa4, 0x93, 0x37, 0x6c, 0x01, 0x70, 0xa9, 0x95, 0x97, 0x0e, 0xeb, 0x8f, 0x93, 0x5f,
        0x41, 0xa3, 0xac, 0xf1, 0x97, 0x59, 0xb4, 0x32, 0x4e, 0x07, 0x43, 0x48, 0xf9, 0xcf, 0x06,
        0x0d, 0x56, 0x9a, 0x00, 0x81, 0xd9, 0xa0, 0xe9, 0x55, 0x10, 0x92, 0x06, 0xa6, 0x6b, 0x9c,
        0x13, 0xd7, 0x6d, 0x41, 0x20, 0x3d, 0xfb, 0x99, 0x7e, 0x36, 0x6c, 0x74, 0x34, 0xcd, 0x35,
        0x58, 0x4b, 0x39, 0xbf, 0x48, 0xd4, 0xbf, 0x90, 0xd1, 0x70, 0x30, 0x08, 0xe4, 0x83, 0xa7,
        0x5f, 0xb6, 0x7a, 0x25, 0xbc, 0xd5, 0x9e, 0xa7, 0x49, 0x36, 0xfc, 0x1d, 0xf0, 0x73, 0x58,
        0x9d, 0xfa, 0xf2, 0xb9, 0x33, 0x57, 0x3e, 0x0e, 0x3b, 0xd8, 0xd3, 0xae, 0x45, 0x4c, 0xaa,
        0x4b, 0x8b, 0x2c, 0x33, 0xd8, 0x20, 0xd5, 0x61, 0xc2, 0xf8, 0x9b, 0x6a, 0x5e, 0xfe, 0x52,
        0xf0, 0x30, 0xe6, 0x94, 0x74, 0x50, 0xff, 0xa7, 0x0f, 0x21, 0x02, 0x20, 0xd7, 0x0f, 0xb0,
        0x66, 0x23, 0xec, 0xa4, 0x60, 0x17, 0x99, 0x10, 0x19, 0xb7, 0xd5, 0x41, 0xf8, 0x7b, 0xfb,
        0xa4, 0xd8, 0xc3, 0xe0, 0xc4, 0x87, 0x7d, 0x66, 0x23, 0x08, 0x24, 0x0f, 0x5a, 0x35, 0x6e,
        0x73, 0xfe, 0xf5, 0x3a, 0x29, 0xdc, 0x52, 0xe6, 0x9d, 0x68, 0x57, 0x10, 0xd3, 0xc4, 0x17,
        0x13, 0x7c, 0x86, 0xaa, 0xab, 0x36, 0xef, 0x9b, 0xb1, 0xe7, 0xa6, 0xb3, 0xe0, 0xa9, 0x34,
        0x30, 0x0b, 0xb1, 0xe4, 0xe6, 0x4f, 0xbf, 0xf4, 0x83, 0xea, 0x9e, 0x8d, 0xba, 0xb2, 0xc4,
        0x62, 0xb8, 0x32, 0x8b, 0x3e, 0xb5, 0x12, 0xc3, 0xb4, 0xac, 0x5d, 0xd4, 0x60, 0x37, 0xa0,
        0x1c, 0x91, 0xaa, 0x24, 0x80, 0xdd, 0xf2, 0xdd, 0xbd, 0x92, 0x4f, 0x6b, 0x41, 0x80, 0x6a,
        0xad, 0xc3
    },
    RSA4096_MODULE_LEN
};
#else
static const rsa_pub_key_t g_ta_verify_pub_key = { { 0 }, 0, { 0 }, 0 };
#endif

static const struct ta_verify_key g_verify_key[] = {
    { PUB_KEY_4096_BITS, PUB_KEY_RELEASE, &g_ta_verify_pub_key }
};

TEE_Result get_ta_verify_pubkey(struct ta_verify_key *key_info)
{
    return query_ta_verify_pubkey(g_verify_key, sizeof(g_verify_key) / sizeof(g_verify_key[0]), key_info);
}
